<template>
  <div>
    <div>
      <h2>人物2</h2>
      <p>姓名: {{ people }}</p>
      fullName: <input type="text" v-model="people" />
      <p>firstName: {{firstName}}</p>
      <p>lastName: {{lastName}}</p>
    </div>
  </div>
</template>

<script>
import { ref, computed } from "vue";

export default {
  setup() {
    let firstName = ref("");
    let lastName = ref("");

    let people = computed({
        get: () => (firstName.value + " " + lastName.value).trim(),
        set: val => {
            console.log("val = ",val);
            let arr = val.split(" ");
            console.log("arr.length = ",arr);
            // 没有空格分割
            if (arr.length == 1) {
                firstName.value = arr[0];
                lastName.value = "";
            } else {
                firstName.value =  arr[0];
                lastName.value = arr[1];
            }
        }
    })

    return { people,firstName,lastName };
  },
};
</script>

<style>
</style>